package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.service.IRegionService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService{

    @Autowired
    private RegionMapper regionMapper;

    @Override
    public List<Region> selectForList(Long parentId) {
        List<Region> list=regionMapper.selectForList(parentId);
        return list;
    }



    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId() != null) {
            regionMapper.updateByPrimaryKey(region);
        }else{
            regionMapper.insert(region);
        }
    }

    @Override
    public void updateStatus(Integer status,Long id) {
        if (status== Region.STATE_NOT) {
            status=Region.STATE_HOT;
        }else{
            status=Region.STATE_NOT;
        }
         regionMapper.updateStatus(status,id);
    }

    @Override
    public List<Region> listAll() {
        return regionMapper.selectAll();
    }


    @Override
    public List<Region> listByState(Integer state) {
         List<Region> list=regionMapper.selectByState(state);
        return list;
    }


}
